// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import {colorType} from "./HeroControl";

const {ccclass, property} = cc._decorator;

@ccclass
export default class KeyControl_red_blue_man extends cc.Component {

    @property({tooltip: "钥匙类型", type: cc.Enum(colorType)})
    keyType: colorType = colorType.red;

    @property({tooltip: "图片资源", type: cc.SpriteFrame})
    keySpriteFrame: cc.SpriteFrame[] = [];

    //精灵组件
    sprite: cc.Sprite = null;

    onLoad () {
        this.sprite = this.node.getComponent(cc.Sprite);
    }

    start () {
        this.init();
        this.anim();
    }

    init(){
        this.sprite.spriteFrame = this.keySpriteFrame[this.keyType];
    }

    anim() {
        this.node.runAction(
            cc.repeatForever(
                    cc.sequence(
                        cc.rotateTo(0.4, 10),
                        cc.rotateTo(0.2, 0),
                        cc.rotateTo(0.4, -10),
                        cc.rotateTo(0.2, 0),
                    )
            )
        );
        this.node.runAction(
            cc.repeatForever(
                cc.sequence(
                    cc.scaleTo(0.3, 1.1, 1.1),
                    cc.scaleTo(0.3, 1,1),
                )
            )
        )
    }


    // update (dt) {}
}
